<script>
	import {
		getQueryString,
		funcUrlDel,
		parseParam
	} from './common/js/util.js'
	import {
		rccLogin
	} from './common/api/index.js';
	export default {
		onLaunch: function() {
			plus.globalEvent.addEventListener('newintent', (e) => {
				var args = plus.runtime.arguments;
				if (args) {
					try {
						let param = parseParam(decodeURIComponent(args))
						if (param.path) {
							plus.runtime.arguments = ""
							args = ""
							uni.navigateTo({
								url: param.path
							})
						} else {
							plus.runtime.arguments = ""
							args = ""
							uni.setStorageSync("collectionFlag", "fail")
						}
					} catch (e) {
						//TODO handle the exception
						plus.runtime.arguments = ""
						args = ""
						uni.setStorageSync("collectionFlag", "fail")
					}
				} else {
					plus.runtime.arguments = ""
					args = ""
					uni.setStorageSync("collectionFlag", "fail")
				}
			});
			// uni.hideTabBar(); 
			// #ifdef H5
			let [appId, xuserId] = window.location.search.split('&');

			let app = getQueryString(window.location.href, 'app')
			let userId = getQueryString(window.location.href, 'userId')
			let mobileNo = getQueryString(window.location.href, 'mobileNo')
			if (app !== null && app.replace("#", '') === 'rcc' && userId != null) { //兼容和市民云H5
				uni.setStorageSync('s_userId', userId.replace("#", ''))
				uni.setStorageSync('s_mobile', mobileNo.replace("#", ''))
				uni.setStorageSync('app_type', app.replace("#", ''))
				uni.setStorageSync('s_login', true)
				window.history.pushState({}, 0, funcUrlDel('userId'));
				window.history.pushState({}, 0, funcUrlDel('mobileNo'));
			} else {
				if (appId) {
					let str1 = appId.split('=')[1].split(',')[1];

					let str3 = appId.split('=')[1].split(',')[0];
					uni.setStorageSync('str1', str1);
					uni.setStorageSync('str3', str3);
				}
				if (xuserId) {
					let str2 = xuserId.split('=')[1];
					uni.setStorageSync('str2', str2);
				}
			}

			// #endif
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary'); //在华为手机会切换成横屏，故必须锁死竖屏，因为rpx是按一边来算的，换边会样式错乱！
			// #endif
			// #ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			})
			// #endif
			uni.getSystemInfo({
				success: (e) => {
					let statusBar = 0
					let customBar = 0

					// #ifdef MP
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + 45
					if (e.platform === 'android') {
						customBar = e.statusBarHeight + 50
					}
					// #endif

					// #ifdef MP-WEIXIN
					statusBar = e.statusBarHeight
					const custom = wx.getMenuButtonBoundingClientRect()
					customBar = custom.bottom + custom.top - e.statusBarHeight
					// #endif

					// #ifdef MP-ALIPAY
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + e.titleBarHeight
					// #endif

					// #ifdef APP-PLUS
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + 45
					// #endif

					// #ifdef H5
					statusBar = 0
					customBar = e.statusBarHeight + 45
					// #endif

					uni.setStorageSync('SET_STATUS_BAR', statusBar)
					uni.setStorageSync('SET_CUSTOM_BAR', customBar)
					uni.setStorageSync('SET_SYSTEM_INFO', e)
				}
			})

		},
		// onShow: function() {
		// 	console.log("----哎")
		// 	// setTimeout(function() {
		// 	// 	let appOpenParam = plus.runtime.arguments
		// 	// 	plus.runtime.arguments = null;
		// 	// 	plus.runtime.arguments = "";
		// 	// 	console.log(appOpenParam,"----------------")
		// 	// 	if (appOpenParam) {
		// 	// 		try {
		// 	// 			let param = parseParam(decodeURIComponent(appOpenParam))
		// 	// 			if (param.path) {
		// 	// 				plus.runtime.arguments = ""
		// 	// 				appOpenParam = ""
		// 	// 				uni.navigateTo({
		// 	// 					url: param.path
		// 	// 				})
		// 	// 			} else {
		// 	// 				uni.setStorageSync("collectionFlag", "fail")
		// 	// 			}
		// 	// 		} catch (e) {
		// 	// 			//TODO handle the exception
		// 	// 			uni.setStorageSync("collectionFlag", "fail")
		// 	// 		}
		// 	// 	} else {
		// 	// 		uni.setStorageSync("collectionFlag", "fail")
		// 	// 	}
		// 	// }, 0);
		// 	setTimeout(() => {
		// 		let orgin = plus.runtime.launcher
		// 		console.log("---", orgin, "----")
		// 		let args = plus.runtime.arguments;
		// 		console.log("----", args, "----")
		// 		if (args) {
		// 			try {
		// 				let param = parseParam(decodeURIComponent(args))
		// 				if (param.path) {
		// 					plus.runtime.arguments = ""
		// 					args = ""
		// 					uni.navigateTo({
		// 						url: param.path
		// 					})
		// 				} else {
		// 					plus.runtime.arguments = ""
		// 					args = ""
		// 					uni.setStorageSync("collectionFlag", "fail")
		// 				}
		// 			} catch (e) {
		// 				//TODO handle the exception
		// 				plus.runtime.arguments = ""
		// 				args = ""
		// 				uni.setStorageSync("collectionFlag", "fail")
		// 			}
		// 		} else {
		// 			plus.runtime.arguments = ""
		// 			args = ""
		// 			uni.setStorageSync("collectionFlag", "fail")
		// 		}
		// 	}, 1000)
		// },
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	@import '~@/common/style/main.scss';
	/*每个页面公共css */
	// @import '@/common/css/common.scss';
	// @import './common/css/uni.css';
</style>